package com.third.controller;

import com.third.annotations.RequirePermission;
import com.third.entity.Goods;
import com.third.result.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @RequestMapping("/all")
    //指定访问该方法时的权限
    @RequirePermission("goods:all")
    public ResponseResult<List<Goods>> all(){

        //模拟从数据库中查询到数据
        List<Goods> goods = Arrays.asList(
                new Goods(1001,"aaa"),
                new Goods(1002,"bbb"),
                new Goods(1003,"ccc")
        );

        //将数据进行封装,返回
        ResponseResult<List<Goods>> responseResult = new ResponseResult<>();
        responseResult.setCode(200);  //状态码   参考HTTP状态码
        responseResult.setMessage("success");
        responseResult.setData(goods);
        //
        return responseResult;
    }
}
